#! /usr/bin/env python
# -*- coding: utf-8 -*-

#用来查询数据库的数据
from sql import sql
import flask

#获取数据
def getinfo(tablename):
	infolist=[]
	DB=sql('')
	hostlist=DB.SelectHost(tablename)
	for hosti in hostlist:
		data=DB.Select(tablename,hosti)
		if(not data==None):
			infolist.append({'host':hosti,'data':data})
	return infolist

#判断表是否存在
def chktable(tablename):
	DB=sql('')
	result=DB.SelectSql('select * from user_tables where table_name=\''+tablename+'\'')
	if(result==None):
		return False
	for i in result:
		return True
	return False

#获得所有表
def gettables():
	tablelist=[]
	DB=sql('')
	result=DB.SelectSql('select table_name from user_tables')
	if(result==None):
		return None
	for row in result:
		result2=DB.SelectSql('SELECT CREATED FROM USER_OBJECTS WHERE OBJECT_NAME=\''+row[0]+'\'')
		for row2 in result2:
			tablelist.append({'name':row[0],'time':'%s'%row2[0]})
	return tablelist